package org.gtugs.omsk.funnycats.engine;

import java.util.ArrayList;
import java.util.List;

import org.gtugs.omsk.funnycats.engine.beans.Position;
import org.gtugs.omsk.funnycats.engine.beans.RectArea;
import org.gtugs.omsk.funnycats.engine.beans.Size;
import org.gtugs.omsk.funnycats.engine.beans.Vector;

public class GameObject{
	
	public GameObject(int maxSpeed, Object userData, RectArea ocuppiedArea) {
		this.maxSpeed = maxSpeed;
		this.userData = userData;
		this.ocuppiedArea = ocuppiedArea;
	}

	public GameObject(int maxSpeed, Object userData, Size size) {
		this.maxSpeed = maxSpeed;
		this.userData = userData;
		this.ocuppiedArea = RectArea.make(Position.make(0.0f, 0.0f), size);
	}
	
	public RectArea getOccupiedArea(){
		return ocuppiedArea;
	}
	
	public Object getUserData(){
		return userData;
	}
	
	public Vector getSpeed() {
		return speed;
	}
	
	public int getMaxSpeed(){
		return maxSpeed;
	}
	
	public Vector getAcceleration() {
		return acceleration;
	}
	
	public RectArea getOcuppiedArea() {
		return ocuppiedArea;
	}

	public RectArea getOcuppiedAreaForPosition(Position position) {
		return RectArea.make(position, ocuppiedArea.size);
	}
	
	public Position getCenterPosition(){
		return ocuppiedArea.getCenterPosition();
	}
			
	public boolean isLifetimeExist(){
		return lifetime != -1f;
	}
	
	public void decreaseLifetime(float dt){
		lifetime -= dt;
	}
	
	public float getLifetime(){
		return lifetime;
	}
	
	public Vector getBasicSpeed(){
		return basicSpeed;
	}
	
	/*package*/ void setBasicSpeed(Vector basicSpeed){
		this.basicSpeed = basicSpeed;
	}
	
	/*package*/ void setSpeed(Vector speed) {
		this.speed = speed;
	}

	/*package*/ void setAcceleration(Vector acceleration) {
		this.acceleration = acceleration;
	}

	/*package*/ void setCenterPosition(Position position) {
		this.ocuppiedArea = RectArea.makeFromCenter(position, ocuppiedArea.size);
	}
	
	/*package*/ void setLifetime(float lifetime){
		this.lifetime = lifetime;
	}
	
	/*package*/ List<GameEffect> getAllEffects(){
		return effects;
	}
	
	/*package*/ void setEffect(GameEffect effect){
		effects.add(effect);
	}
	
	/*package*/ void removeAllEffects(){
		effects.clear();
		
		setSpeed(Vector.make(basicSpeed.x, basicSpeed.y));
		setAcceleration(Vector.zeroVector());
	}
	
	private Object userData;
	private Vector basicSpeed;
	private final int maxSpeed;
	private float lifetime = -1f;
	private RectArea ocuppiedArea = RectArea.makeEmpty();
	private Vector speed = Vector.zeroVector();
	private Vector acceleration = Vector.zeroVector();
	
	private List<GameEffect> effects = new ArrayList<GameEffect>();
}
